﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace ProgNetComponentsDx.Forms
{
    public partial class FormMemoInput : XtraForm
    {
        public FormMemoInput()
        {
            InitializeComponent();
            this.Text = Application.ProductName;
        }

        public FormMemoInput(string txt)
            : this()
        {
            EditValue = txt;
            this.memoEdit1.Text = txt;
            this.Text = Application.ProductName;
        }

        public bool ReadOnly
        {
            get { return memoEdit1.Properties.ReadOnly; }
            set
            {
                memoEdit1.Properties.ReadOnly = value;
                UpdateButtons();
            }
        }
        protected virtual void UpdateButtons()
        {
            if (ReadOnly)
            {
                btnCancel.Visible = false;
                btnOk.Left = btnCancel.Left;
            }
            else
            {
                btnCancel.Visible = true;
                btnOk.Left = btnCancel.Left - btnOk.Width - 5;
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
        public string EditValue
        {
            get;
            private set;
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (ValidateAll())
            {
                EditValue = memoEdit1.Text;
                DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
        protected virtual bool ValidateAll()
        {
            return true;
        }
    }
}
